package model.bean;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import util.Constants;

@NamedQueries({ @NamedQuery(name = "autenticarLogin", query = "SELECT u FROM Usuario u "
		+ " WHERE u.login = :login " 
		+ " AND u.senha = :senha "
),@NamedQuery(name = "findByLogin", query = "SELECT u FROM Usuario u "
		+ " WHERE u.login = :login " 
),
		@NamedQuery(name = "findByCPF", query = "SELECT u FROM Usuario u "
		+ " WHERE u.cpf = :cpf " 
) })
@Entity
@Table(name = Constants.DATABASE_TABLE_USUARIO, schema = Constants.DATABASE_NOME)
public class Usuario implements Serializable {

	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private int idUsuario;

	@Column(name = "cpf", unique = true, insertable = true, updatable = true, length = 14)
	private String cpf;

	@Column(name = "nome", insertable = true, updatable = true, length = 50)
	private String nome;

	@Column(name = "email", insertable = true, updatable = true, length = 50)
	private String email;

	@Column(name = "login", unique = true, insertable = true, updatable = true, length = 20)
	private String login;

	@Column(name = "senha", insertable = true, updatable = true, length = 20)
	private String senha;

	@Column(name = "sexo", insertable = true, updatable = true, length = 9)
	private String sexo;

	@ManyToOne
	@Fetch(FetchMode.JOIN)
	@JoinColumn(referencedColumnName = "idNucleo")
	private Nucleo nucleo;

	@Column(name = "perfil", insertable = true, updatable = true, length = 20)
	private String perfil;

	public Usuario() {

	}

	public Usuario(int idUsuario, String cpf, String nome, String email,
			String login, String senha, String sexo, Nucleo nucleo, String perfil) {
		this.idUsuario = idUsuario;
		this.cpf = cpf;
		this.nome = nome;
		this.email = email;
		this.login = login;
		this.senha = senha;
		this.sexo = sexo;
		this.nucleo = nucleo;
		this.perfil = perfil;
	}

	public int getIdUsuario() {
		return idUsuario;
	}

	public void setIdUsuario(int idUsuario) {
		this.idUsuario = idUsuario;
	}

	public String getCpf() {
		return cpf;
	}

	public void setCpf(String cpf) {
		this.cpf = cpf;
	}

	public String getNome() {
		return nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getLogin() {
		return login;
	}

	public void setLogin(String login) {
		this.login = login;
	}

	public String getSenha() {
		return senha;
	}

	public void setSenha(String senha) {
		this.senha = senha;
	}

	public String getSexo() {
		return sexo;
	}

	public void setSexo(String sexo) {
		this.sexo = sexo;
	}

	public Nucleo getNucleo() {
		return nucleo;
	}

	public void setNucleo(Nucleo nucleo) {
		this.nucleo = nucleo;
	}

	public String getPerfil() {
		return perfil;
	}

	public void setPerfil(String perfil) {
		this.perfil = perfil;
	}

}
